{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n",
     "is_executing": true
    }
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"../\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from data.fashionIQ import FashionIQDataset, FashionIQTestQueryDataset\n",
    "\n",
    "clothing_types = [\"dress\", \"shirt\", \"toptee\"]\n",
    "datasets = []\n",
    "for clothing in clothing_types:\n",
    "    datasets.append(FashionIQDataset(clothing_type=clothing))\n",
    "    datasets.append(FashionIQTestQueryDataset(clothing_type=clothing))\n",
    "caption_positions = [2 for _ in datasets]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from language.vocabulary import SimpleVocabulary\n",
    "from language.tokenizers import NltkTokenizer\n",
    "from language.utils import create_read_func, create_write_func"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 11970/11970 [00:55<00:00, 216.73it/s]\n",
      "100%|██████████| 4034/4034 [00:09<00:00, 437.02it/s]\n",
      "100%|██████████| 11976/11976 [00:56<00:00, 213.67it/s]\n",
      "100%|██████████| 4076/4076 [00:09<00:00, 420.40it/s]\n",
      "100%|██████████| 12054/12054 [00:57<00:00, 208.97it/s]\n",
      "100%|██████████| 3922/3922 [00:09<00:00, 409.20it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<language.vocabulary.SimpleVocabulary at 0x7fb4ef47fa90>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tokenizer = NltkTokenizer()\n",
    "write_func = create_write_func('fashion_iq_vocab.pkl')\n",
    "read_func = create_read_func('fashion_iq_vocab.pkl')\n",
    "SimpleVocabulary.create_and_store_vocabulary_from_datasets(datasets, tokenizer, write_func, caption_pos=caption_positions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4676\n"
     ]
    }
   ],
   "source": [
    "vocab = SimpleVocabulary.create_vocabulary_from_storage(read_func)\n",
    "print(len(vocab))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3 (ipykernel)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}